package pl.lsierant.j2me.bipacz.screens;

import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

import pl.lsierant.j2me.bipacz.BipaczMidlet;

public class MenuScreen extends List implements CommandListener {
    BipaczMidlet parent;

    private Command exitCommand;

    public MenuScreen(BipaczMidlet midlet) {
        super("Menu", Choice.IMPLICIT);
        parent = midlet;

        exitCommand = new Command("Exit", Command.EXIT, 1);
        init();
    }

    public void commandAction(Command cmd, Displayable disp) {
        int type = cmd.getCommandType();
        if (type == Command.SCREEN) {
            Displayable nextScreen = this;
            switch (getSelectedIndex()) {
            case 0:
                nextScreen = new IntervalTimerScreen(parent);
                break;
            case 1:
                nextScreen = new TestScreen(parent, this);
                break;
            default:
                break;
            }
            Display.getDisplay(parent).setCurrent(nextScreen);
        } else if (type == Command.EXIT) {
            parent.exit();
        }

    }

    private void init() {
        append("Interval Timer", null);
        append("Tests", null);
        addCommand(exitCommand);
        setCommandListener(this);
    }
}
